<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        保养模块-保养项目
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../css/main.css" media="all">
    <script type="text/javascript" src="../../../lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="../../../css/bootstrap.css">
    <link rel="stylesheet" href="../../../lib/layui/css/layui_2.5.7.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .layui-table-page select {
            height: 22px;
        }
    </style>
</head>

<body>
<div>

    <div class="layui-card-body" id="app">
        <button type="button" style="float: right;margin-left: 20px;" class="layui-btn" id="test3"><i class="layui-icon"></i>批量上传</button>
        <button style="float: right;" class="layui-btn" onclick="add()"><i class="layui-icon"></i>添加
        </button>
        <span>模板名称：{{modelname}}</span>
        <table class="layui-table" id="test" lay-filter="test">
        </table>
    </div>
    <br><br><br><br><br><br>
</div>
</body>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="view">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script type="text/javascript" src="../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../js/pub.js"></script>
<script type="text/javascript" src="../../../lib/layui/layui2.5.7.js"></script>
<script type="text/javascript" src="../../../js/vue.min.js"></script>
<!-- <script src="lib/layui/layui.js" charset="utf-8"></script> -->
<script src="../../../js/x-layui.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>



<script>


    var recordId = getQueryVariable("recordId");

    var vm = new Vue({
        el: "#app",
        data: {
            modelname: null,
            modelid:null,
        },
        created() {
            let request = {
                url: 'maintenance/maintainmodel/findOne',
                data:{id: recordId,userId:$userId},
                method: "POST",
            };
            sendRequest(request, (res) => {
                this.modelname = res.data.name;
                this.modelid = res.data.id;
            });

        }
    });

    layui.use(['upload', 'element', 'laypage', 'layer', 'form','table'], function () {

        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        lement = layui.element;//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        upload = layui.upload;
        var form = layui.form;
        okLoading.close($);
        var table = layui.table;

        //方法级渲染
        var t1 = table.render({
            elem: '#test',
            url: $baseUrl + 'maintenance/maintainprogram/list',
            where: {
                modelId: recordId,
                userId:$userId
            },
            headers: {
                token: $token
            }
            , toolbar: '#toolbarDemo',

            // toolbar: true,
            cols: [
                [

                    {
                        title: '项目',
                        width: '30%',
                        templet(item) {
                            return item.program== undefined ? "" : item.program;
                        }

                    },
                    {
                        field: 'addressAndTelephoneNumber',
                        title: '要求',
                        width: '30%',
                        templet(item) {
                            return item.requirement== undefined ? "" : item.requirement;
                        }


                    },
                    /*{
                        field: 'bankAndAccountNumber',
                        title: '部位',
                        width: '15%',
                        templet(item) {
                            return item.position.name== undefined ? "" : item.position.name;
                        }

                    },*/
                    {
                        field: 'bankAndAccountNumber',
                        title: '类型',
                        width: '20%',
                        templet(item) {
                            return item.type== undefined ? "" : item.type;
                        }


                    },
                   /* {
                        field: 'bankAndAccountNumber',
                        title: '可选',
                        width: '15%',
                        templet(item) {
                            return item.ischoice== undefined ? "" : item.ischoice;
                        }

                    },*/


                    {
                        field: 'status',
                        title: '操作',
                        templet: '#barDemo',
                        fixed: 'right',
                        width: '20%'
                    }]
            ],
            response: {
                statusName: 'code' //规定数据状态的字段名称，默认：code
                ,
                statusCode: 0 //规定成功的状态码，默认：0
                ,
                msgName: 'msg' //规定状态信息的字段名称，默认：msg
                ,
                countName: 'total' //规定数据总数的字段名称，默认：count
                ,
                dataName: 'data', //规定数据列表的字段名称，默认：data
            },
            id: 'test',
            height: 'auto',
            even: true,
            done: function (res, curr, count) {
                //是否有权限或权限是否失效
                // authorizeState();

            }
        });

        var index = null;
        upload.render({
            elem: '#test3',
            url:baseHead + "/maintenance/maintainprogram/importExcel",
            headers: {
                "token": $token,
            },
            data: {
                userId: $userId,
                modelId:recordId
            }
            ,accept: 'file' //普通文件
            ,choose:function (obj) {
                index = layer.load(1); //换了种风格

            }
            ,done: function(res){

                layer.close(index);
                t1.reload();
                if (res.code === 0) {

                    layer.msg("批量添加成功", {
                        icon: 1
                    });
                    t1.reload();

                } else {
                    layer.alert(res.msg, {
                        icon: 2
                    });
                }
            }
        });


        //监听工具条
        table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            let data = obj.data; //获得当前行数据
            let layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if (layEvent === 'del') { //删除
                layer.confirm('是否确认删除 ？', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    let request = {
                        url: "maintenance/maintainprogram/del/" + data.id,
                        data:{userId:$userId},
                        method: "DELETE",
                    };
                    sendRequest(request, (data) => {
                        if (data.code === 0) {
                            layer.msg("删除成功", {
                                icon: 1
                            });
                            t1.reload();
                        } else {
                            layer.msg("删除失败，请稍后再试！", {
                                icon: 5
                            });
                        }
                    });
                    layer.close(index);
                });
            } else if (layEvent === 'view') { //编辑
                admin_add('编辑信息', 'mainternace_program_eidt.html?recordId=' + data.id)
            }
        });

    });

    function reload(value) {
        table.reload('test', {
            where: {
                modelId: recordId,
            }
        });
    }

    function admin_add(title, url, w, h) {
        x_admin_show(title, url, w, h);
    }


    function add(){
        admin_add('添加保养项目信息','mainternace_program_add.html?recordId='+vm.modelid);
    }
</script>



</html>
